package com.cooper.scheduler.job;

import java.util.Set;

import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;

import com.cooper.resource.IResourceManager;

/**
 * 
* @Description: 
* @version: v1.0.0
* @author: tianlg
* @date: Oct 18, 2014 9:51:20 PM
*
* Modification History:
* Date         Author          Version            Description
*---------------------------------------------------------*
* Oct 18, 2014     tianlg          v1.0.0
 */
public class SyncResourceManagerJob implements Job {

	private Logger logger = LoggerFactory.getLogger(this.getClass());
	
	@Autowired
	private IResourceManager resourceManager;
	
	@Override
	public void execute(JobExecutionContext context) throws JobExecutionException {
		logger.info("Start refresh resource manager.");
		Set<String> resNameSet = this.resourceManager.getResNameSet();
		for(String resName: resNameSet){
			try {
				this.resourceManager.refresh(resName);
			} catch (Exception e) {
				logger.error("refresh resource item {} error.", resName, e);
				e.printStackTrace();
			}
		}
		logger.info("End refresh resource manager.");
	}

}
